package 公司真题.瑛太莱;

import java.util.Iterator;
import java.util.Scanner;
import java.util.Stack;

public class _计算器 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String midSeq = sc.nextLine().trim();
        char[] arr = midSeq.toCharArray();
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < arr.length; i++) {
            if (arr[i] != ' ') {
                sb.append(arr[i]);
            }
        }
        midSeq = sb.toString();
        System.out.println(midSeq);
        String postSeq = midToPost(midSeq);
        System.out.println(postSeq);
        int res = myCalculate(postSeq);
        System.out.println(res);
    }

    private static int myCalculate(String postSeq) {
        Stack<Integer> stack = new Stack<>();
        char[] arr = postSeq.toCharArray();
        int index = 0;
        int res = arr[0] - 48;
        while (index < arr.length) {
            if (arr[index] >= 48 && arr[index] <= 57) { // 是数字
                stack.push(arr[index] - 48);
            } else {
                if (arr[index] == '+') {
                    int temp1 = stack.pop();
                    int temp2 = stack.pop();
                    stack.push(temp1 + temp2);
                } else if (arr[index] == '-') {
                    int temp1 = stack.pop();
                    int temp2 = stack.pop();
                    stack.push(temp2 - temp1);
                } else if (arr[index] == '*') {
                    int temp1 = stack.pop();
                    int temp2 = stack.pop();
                    stack.push(temp1 * temp2);
                } else if (arr[index] == '/') {
                    int temp1 = stack.pop();
                    int temp2 = stack.pop();
                    stack.push(temp2 / temp1);
                }
            }
            index++;
        }
        res = stack.pop();
        return res;
    }

    private static String midToPost(String midSeq) {
        Stack<Character> S1 = new Stack<Character>();
        Stack<Character> S2 = new Stack<Character>();

        int len = midSeq.length();
        int index = 0;
        while (index < len) {
            char c = midSeq.charAt(index);
            switch (c) {
                case '(':
                    S1.push(c);
                    break;
                case ')':
                    while (S1.peek() != '(')
                        S2.push(S1.pop());
                    S1.pop();
                    break;
                case '+':
                case '-':
                    while (!S1.empty() && S1.peek() != '(')
                        S2.push(S1.pop());
                    S1.push(c);
                    break;
                case '*':
                case '/':
                    while (!S1.empty() && S1.peek().toString().matches("[*/]"))
                        S2.push(S1.pop());
                    S1.push(c);
                    break;
                default:
                    S2.push(c);
            }
            index++;
        }
        while (!S1.empty())
            S2.push(S1.pop());
        Iterator<Character> iter = S2.iterator();
        StringBuffer postSeq = new StringBuffer();
        while (iter.hasNext())
            postSeq.append(iter.next());
        return postSeq.toString();
    }
}
